use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

/// 分页实例VO结构体
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct PageInstanceVo<T> {
    /// 总数
    #[schema(example = 1)]
    pub total: usize,
    /// 数据列表
    #[schema(example = json!([{}]))]
    pub list: Vec<T>,
}

impl<T> PageInstanceVo<T>
where
    T: Serialize + for<'de> Deserialize<'de>,
{
    pub fn new(total: usize, list: Vec<T>) -> Self {
        Self { total, list }
    }
}

impl<T> Default for PageInstanceVo<T>
where
    T: Serialize + for<'de> Deserialize<'de>,
{
    fn default() -> Self {
        PageInstanceVo {
            total: 0,
            list: Vec::new(),
        }
    }
}
